import 'package:tiktokadult/hj_model/actress_info.dart';
import 'package:tiktokadult/hj_model/home/module_detail_model.dart';
import 'package:tiktokadult/hj_model/video_model.dart';

import '../cartoon_media_info.dart';

class CartoonMoreListModel {
  bool? hasNext;
  List<CartoonMediaInfo>? list;
  AllSection? section;
  int? total;
  List<NovelSection>? sectionList; //小说分类

  CartoonMoreListModel({
    this.hasNext,
    this.list,
    this.total,
    this.section,
    this.sectionList,
  });

  CartoonMoreListModel.fromJson(dynamic json) {
    hasNext = json['hasNext'];
    if (json['list'] != null) {
      list = [];
      json['list'].forEach((v) {
        list?.add(CartoonMediaInfo.fromJson(v));
      });
    }
    if (json['allSection'] != null) {
      sectionList = [];
      json['allSection'].forEach((v) {
        sectionList?.add(NovelSection.fromJson(v));
      });
    }
    section = AllSection.fromJson(json['section'] ?? {});

    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['hasNext'] = hasNext;
    if (list != null) {
      map['list'] = list?.map((v) => v.toJson()).toList();
    }
    map['total'] = total;
    return map;
  }
}

class NovelSection {
  String? sectionID;
  String? sectionName;
  NovelSection.fromJson(dynamic json) {
    sectionID = json['sectionID'];
    sectionName = json['sectionName'];
  }
}

class ShortMediaMoreListModel {
  bool? hasNext;
  List<AllMediaInfo>? list;
  int? total;

  ShortMediaMoreListModel({
    this.hasNext,
    this.list,
    this.total,
  });

  ShortMediaMoreListModel.fromJson(dynamic json) {
    hasNext = json['hasNext'];
    if (json['list'] != null) {
      list = [];
      json['list'].forEach((v) {
        list?.add(AllMediaInfo.fromJson(v));
      });
    }
    total = json['total'];
  }
}

class AllMediaInfo {
  List<Content>? contents;
  int? countBrowse;
  int? countCollect;
  int? countComment;
  int? countDisLike;
  int? countLike;
  int? countPurchases;
  int? countView;
  String? createdAt;
  int? direction;
  int? freeTime;
  bool? hasFollow;
  String? horizontalCover;
  List<ActressInfo>? allActress;

  String? get coverH {
    return (horizontalCover?.isNotEmpty == true) ? horizontalCover : verticalCover;
  }

  String? get coverV {
    return (verticalCover?.isNotEmpty == true) ? verticalCover : horizontalCover;
  }

  String? id;
  int? kind;
  String? mId;
  VidStatus? mediaStatus;
  String? mediaType;
  String? moduleName;
  int? number;
  int? permission;
  bool? permissionIconHide;
  int? price;
  String? sId;
  String? sectionName;
  int? sectionSort;
  int? sellType;
  int? sortCode;
  int? status;
  String? summary;
  List<TagsBean>? tagDetails;
  // List<AllRankingAllActress>? allActress;
  List<String>? tags;

  String get tagsAllDesc {
    String desc = "";
    if (tagDetails?.isNotEmpty == true) {
      desc = tagDetails?.first.name ?? "";
    }
    for (int i = 1; i < (tagDetails?.length ?? 0); i++) {
      desc += "、${tagDetails![i].name ?? ""}";
    }
    return desc;
  }

  String? title;
  int? totalEpisode; //总集数
  int? currentEpisode; //总集数

  int? updateStatus; //0 默认 1、更新中 2、已完结
  String? updateTime;
  String? verticalCover;

  AllMediaInfo({
    this.contents,
    this.countBrowse,
    this.countCollect,
    this.countComment,
    this.countDisLike,
    this.countLike,
    this.countPurchases,
    this.countView,
    this.allActress,
    this.createdAt,
    this.direction,
    this.freeTime,
    this.hasFollow,
    this.horizontalCover,
    this.id,
    this.kind,
    this.mId,
    this.mediaStatus,
    this.mediaType,
    this.moduleName,
    this.number,
    this.permission,
    this.permissionIconHide,
    this.price,
    this.sId,
    this.sectionName,
    this.sectionSort,
    this.sellType,
    this.sortCode,
    this.status,
    this.summary,
    this.tagDetails,
    this.tags,
    this.title,
    this.totalEpisode,
    this.currentEpisode,
    this.updateStatus,
    this.updateTime,
    this.verticalCover,
  });

  //获取标签
  String getTagsString() {
    String value = '';
    if (tagDetails != null && tagDetails!.isNotEmpty) {
      for (TagsBean element in tagDetails!) {
        value = '$value${element.name}、';
      }
      value = value.substring(0, value.length - 1);
    }
    return value;
  }

  // String getUpdateString() {
  //   String unit = '集';
  //   if (mediaType == 'image') {
  //     unit = '话';
  //   }
  //   if (updateStatus == 0 || updateStatus == 1) {
  //     return '连载中';
  //   } else if (updateStatus == 2) {
  //     return '已完结';
  //   } else {
  //     return '';
  //   }
  // }

  //集数状态描述
  String get episodeNumberStatus {
    if (updateStatus == 2) {
      return '共$totalEpisode话';
    } else {
      return '更新${currentEpisode != 0 ? currentEpisode : totalEpisode}话';
    }
  }

  //更新状态
  String get getUpdateString {
    if (updateStatus == 2) {
      return '已完结';
    } else {
      return '连载中';
    }
  }

  AllMediaInfo.fromJson(Map<String, dynamic> json) {
    contents = json["contents"] == null ? [] : List<Content>.from(json["contents"]!.map((x) => Content.fromJson(x)));
    countBrowse = json["countBrowse"];
    countCollect = json["countCollect"];
    countComment = json["countComment"];
    countDisLike = json["countDisLike"];
    countLike = json["countLike"];
    countPurchases = json["countPurchases"];
    countView = json["countView"];
    createdAt = json["createdAt"];
    direction = json["direction"];
    freeTime = json["freeTime"];
    hasFollow = json["hasFollow"];
    horizontalCover = json["horizontalCover"];
    allActress = json["actresses"] == null ? [] : List<ActressInfo>.from(json["actresses"]!.map((x) => ActressInfo.fromJson(x)));
    id = json["id"];
    kind = json["kind"];
    mId = json["mId"];
    mediaStatus = json["mediaStatus"] == null ? null : VidStatus.fromMap(json["mediaStatus"]);
    mediaType = json["mediaType"];
    moduleName = json["moduleName"];
    number = json["number"];
    permission = json["permission"];
    permissionIconHide = json["permissionIconHide"];
    price = json["price"];
    sId = json["sId"];
    sectionName = json["sectionName"];
    sectionSort = json["sectionSort"];
    sellType = json["sellType"];
    sortCode = json["sortCode"];
    status = json["status"];
    summary = json["summary"];
    tagDetails = json["tagDetails"] == null ? [] : List<TagsBean>.from(json["tagDetails"]!.map((x) => TagsBean.fromMap(x)));
    tags = json["tags"] == null ? [] : List<String>.from(json["tags"]!.map((x) => x));
    title = json["title"];
    totalEpisode = json["totalEpisode"];
    currentEpisode = json['currentEpisode'];
    updateStatus = json["updateStatus"];
    updateTime = json["updateTime"];
    verticalCover = json["verticalCover"];
  }
}

class Content {
  String? audioUrl;
  int? countBrowse;
  int? countCollect;
  int? countComment;
  int? countDisLike;
  int? countLike;
  int? countPurchases;
  String? createdAt;
  int? episodeNumber;
  int? height;
  String? id;
  int? listenPermission;
  String? md5;
  String? mediaId;
  int? mediaSize;
  VidStatus? mediaStatus;
  String? name;
  int? playTime;
  int? price;
  int? ratio;
  String? text;
  String? updateTime;
  List<String>? urlSet;
  String? videoUrl;
  int? weight;

  Content({
    this.audioUrl,
    this.countBrowse,
    this.countCollect,
    this.countComment,
    this.countDisLike,
    this.countLike,
    this.countPurchases,
    this.createdAt,
    this.episodeNumber,
    this.height,
    this.id,
    this.listenPermission,
    this.md5,
    this.mediaId,
    this.mediaSize,
    this.mediaStatus,
    this.name,
    this.playTime,
    this.price,
    this.ratio,
    this.text,
    this.updateTime,
    this.urlSet,
    this.videoUrl,
    this.weight,
  });

  Content.fromJson(Map<String, dynamic> json) {
    audioUrl = json["audioUrl"];
    countBrowse = json["countBrowse"];
    countCollect = json["countCollect"];
    countComment = json["countComment"];
    countDisLike = json["countDisLike"];
    countLike = json["countLike"];
    countPurchases = json["countPurchases"];
    createdAt = json["createdAt"];
    episodeNumber = json["episodeNumber"];
    height = json["height"];
    id = json["id"];
    listenPermission = json["listenPermission"];
    md5 = json["md5"];
    mediaId = json["mediaId"];
    mediaSize = json["mediaSize"];
    mediaStatus = json["mediaStatus"] == null ? null : VidStatus.fromMap(json["mediaStatus"]);
    name = json["name"];
    playTime = json["playTime"];
    price = json["price"];
    ratio = json["ratio"];
    text = json["text"];
    updateTime = json["updateTime"];
    urlSet = json["urlSet"] == null ? [] : List<String>.from(json["urlSet"]!.map((x) => x));
    videoUrl = json["videoUrl"];
    weight = json["weight"];
  }

  Map<String, dynamic> toJson() => {
        "audioUrl": audioUrl,
        "countBrowse": countBrowse,
        "countCollect": countCollect,
        "countComment": countComment,
        "countDisLike": countDisLike,
        "countLike": countLike,
        "countPurchases": countPurchases,
        "createdAt": createdAt,
        "episodeNumber": episodeNumber,
        "height": height,
        "id": id,
        "listenPermission": listenPermission,
        "md5": md5,
        "mediaId": mediaId,
        "mediaSize": mediaSize,
        "mediaStatus": mediaStatus?.toJson(),
        "name": name,
        "playTime": playTime,
        "price": price,
        "ratio": ratio,
        "text": text,
        "updateTime": updateTime,
        "urlSet": urlSet == null ? [] : List<dynamic>.from(urlSet!.map((x) => x)),
        "videoUrl": videoUrl,
        "weight": weight,
      };
}

class MediaSearchListModel {
  bool? hasNext;
  List<CartoonMediaInfo>? list;
  List<CartoonMediaInfo>? tagMedia;
  String? tagId;
  int? total;

  MediaSearchListModel({this.hasNext, this.list, this.total, this.tagId});

  MediaSearchListModel.fromJson(dynamic json) {
    hasNext = json['hasNext'];
    list = (json['list'] as List?)?.map((v) => CartoonMediaInfo.fromJson(v)).toList();
    tagMedia = (json['tagMedia'] as List?)?.map((v) => CartoonMediaInfo.fromJson(v)).toList();
    tagId = json['tagId'];
    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['hasNext'] = hasNext;

    map['list'] = list?.map((v) => v.toJson()).toList();

    map['total'] = total;
    return map;
  }
}

class AcgSectionModel {
  bool? hasNext;
  List<AcgSectionItem>? list;

  AcgSectionModel({this.hasNext, this.list});

  AcgSectionModel.fromJson(Map<String, dynamic> json) {
    hasNext = json['hasNext'];
    if (json['list'] != null) {
      list = <AcgSectionItem>[];
      json['list'].forEach((v) {
        list!.add(AcgSectionItem.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['hasNext'] = this.hasNext;
    if (this.list != null) {
      data['list'] = this.list!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class AcgSectionItem {
  int? count;
  String? cover;
  String? id;
  String? name;
  String? portrait;
  int? type;
  int? userId;

  AcgSectionItem({this.count, this.cover, this.id, this.name, this.portrait, this.type, this.userId});

  AcgSectionItem.fromJson(Map<String, dynamic> json) {
    count = json['count'];
    cover = json['cover'];
    id = json['id'];
    name = json['name'];
    portrait = json['portrait'];
    type = json['type'];
    userId = json['userId'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['count'] = this.count;
    data['cover'] = this.cover;
    data['id'] = this.id;
    data['name'] = this.name;
    data['portrait'] = this.portrait;
    data['type'] = this.type;
    data['userId'] = this.userId;
    return data;
  }

  toAllSectionModel() {
    AllSection model = AllSection();
    model.sectionName = name;
    model.sectionID = id;
    model.sectionTitle = name;
    return model;
  }
}
